import React from 'react'
import { connect } from 'react-redux'
import {Tabs, Divider, Form, Radio, Button, Modal, message} from 'antd';
import {messages} from "share/common";
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
import DevelopmentPlatformService from 'containers/setting/development-platform/development-platform.service'

class WeChat extends React.Component{
  constructor(props){
    super(props);
    this.state = {
      setting: {},
      loading: false,
    };
  }

  componentWillMount(){
    this.getSetting();
  }


  getSetting = () => {
    DevelopmentPlatformService.getSetting()
      .then((res) => {
        this.setState({
          setting: res.data,
        })
      })
  };

  saveSetting = () => {
    this.setState({
      loading: true,
    });
    this.props.form.validateFieldsAndScroll((err, values) => {
      if(!err){
        DevelopmentPlatformService.saveSetting(values)
          .then((res) => {
            this.getSetting();
            this.setState({
              loading: false,
            });
            message.success(messages('basic-12.key1')/*保存成功*/);
          }).catch(err => {
          this.setState({
            loading: false,
          })
        })
      }
    })
  };

  render () {
    const {getFieldDecorator} = this.props.form;
    const formItemLayout = {
      labelCol: {span: 5},
      wrapperCol: {span: 16, offset: 1},
    };
    const {setting, loading} = this.state;
    const {disabled} = this.props;
    return (
      <div className="left-edge-gap">
        <div className="bottom-gap">{messages('basic-12.key10')/*设置说明:  基于企业微信平台相关的功能设置，应用范围全租户*/}</div>
        <Form className="new-form">
          <div className="standard-divider-title">{messages('basic-12.key11')/*消息推送设置*/}</div>
          <FormItem {...formItemLayout} label={messages('basic-12.key12')/*审批提醒消息类型*/}>
            {getFieldDecorator('weChatMsgType',{
              initialValue: setting.weChatMsgType
            })(
              <RadioGroup>
                <Radio value={1}>{messages('basic-12.key13')/*文本卡片*/}</Radio>
                <Radio value={2}>{messages('basic-12.key14')/*任务卡片*/}</Radio>
              </RadioGroup>
            )}
            <div>{messages('basic-12.key15')/*文本卡片不带审批处理状态，任务卡片仅企业微信2.8.2及以上版本支持*/}</div>
          </FormItem>
          <Button type="primary"
                  disabled={disabled}
                  onClick={this.saveSetting}
                  style={{marginBottom: 20}}
                  loading={loading}>
            {/*保存*/}
            {messages('common.save')/*保存*/}
          </Button>
        </Form>
      </div>
    )

  }


}
WeChat.contextTypes = {
  router: React.PropTypes.object,
};
function mapStateToProps(state) {
  return {
  }
}

const WrappedWeChat = Form.create()(WeChat);
export default connect(mapStateToProps)(WrappedWeChat);
